package com.linkage.jz.bankruptcy.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.bean.SearchDeclarationBean;
import com.linkage.jz.bankruptcy.utils.Utils;
import com.seapeak.recyclebundle.BaseHolder;
import com.seapeak.recyclebundle.BaseRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class SearchDeclarationListAdapter extends BaseRecyclerAdapter<BaseHolder> {


    private Context                     mContext;
    private List<SearchDeclarationBean> mList = new ArrayList<>();

    private LayoutInflater mLayoutInflater;

    public SearchDeclarationListAdapter( Context mContext, List<SearchDeclarationBean> mList ) {
        this.mContext = mContext;
        this.mList = mList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public BaseHolder onCreateViewHolder( @NonNull ViewGroup parent, int viewType ) {
        View view = mLayoutInflater.inflate(R.layout.item_search_declaration_list, parent, false);
        return new SearchDataViewHolder(mContext, view);
    }

    @Override
    public void onBindViewHolder( BaseHolder holder, int position ) {
        super.onBindViewHolder(holder, position);
        SearchDeclarationBean bean = mList.get(position);
        if (holder instanceof SearchDataViewHolder) {
            SearchDataViewHolder viewHolder = (SearchDataViewHolder) holder;
            viewHolder.onBindData(bean);
        }
    }

    @Override
    public int getItemCount() {
        return mList != null ? mList.size() : 0;
    }

    public static class SearchDataViewHolder extends BaseHolder {

        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_tag)
        TextView tvTag;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_deal_status)
        TextView tvDealStatus;

        private Context mContext;

        public SearchDataViewHolder( Context context, View view ) {
            super(view);
            mContext = context;
            ButterKnife.bind(this, view);
        }

        private void onBindData( SearchDeclarationBean item ) {
            if (item == null) return;
            tvTitle.setText(String.valueOf(item.getTitle()));
            tvTime.setText(Utils.timeStamp2Date(item.getTime() * 1000, "yyyy-MM-dd HH:mm:ss"));

            if(item.getTitle().indexOf("异议")==-1) {
                tvDealStatus.setText(item.getStatus() == 1 ? "已审查" : "待审查");
            }else{
                tvDealStatus.setText(item.getStatus() == 1 ? "已回复" : "待回复");
            }
            tvDealStatus.setTextColor(ContextCompat.getColor(mContext, item.getStatus() == 1 ? R.color.color_289F9F : R.color.color_FD9F4E));

            tvTag.setVisibility(item.getOnlineStatus() == 2 ? View.VISIBLE : View.GONE);
            tvStatus.setVisibility(item.getOverdue() == 2 ? View.VISIBLE : View.GONE);
        }
    }
}
